<template>
  <div class="question-box">
    <secQuestion ref="questionRef" :data="questionData" :customRule="true" :card="true">
      <div class="question-card-title" slot="card-title">答题卡</div>
      <div slot="card-btn">
        <el-button
          type="primary"
          class="submit-que"
          @click="subQuestion"
          :disabled="!(status.includes(data.status) && data.admin == '1')"
          >提交问卷</el-button
        >
      </div>
      <div slot="title" class="question-title">{{ data.domain }}（{{ data.domainName }}） 审计指标设定（调查问卷）</div>
      <!-- <div class="question-title" slot="title">敏感场景配置</div> -->
    </secQuestion>
  </div>
</template>

<script>
import { getQuestionsApi, saveQuestionsApi } from "api/evaluateApi";
export default {
  name: "questionnaire",
  props: {},
  components: {},
  data() {
    return {
      status: ["12", "13"],
      query: {},
      data: {},
      questionData: [], //调查问卷界面展示题目的数据
    };
  },
  computed: {},
  mounted() {
    this.query = this.$route.query;
    getQuestionsApi({ reportId: this.$route.query.reportId }).then((res) => {
      this.data = res.data;
      this.questionData = this.data.questions;
    });
  },
  methods: {
    //提交问卷
    subQuestion() {
      let data = this.$refs.questionRef.submit();
      if (!data) return; //有必填项没填写，如果都填写了，data是选择过的data数据
      this.saveQuestions(data);
    },
    //提交选择的问卷 给后台一份
    saveQuestions(data) {
      saveQuestionsApi({ reportId: this.$route.query.reportId, answers: data }).then((res) => {
        let state = this.message.state(res);
        if (!state) return;
        let path = this.$route.query.type === "special" ? "/evaluate/manage/special/detail" : "/evaluate/manage/detail";
        this.$router.push({
          path,
          query: {
            id: this.$route.query.reportId,
            assetId: this.data.assetId,
          },
        });
      });
    },
  },
  watch: {},
};
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类
@import "@/styles/question.scss";
</style>
